package com.fxz.bean.xml;

import com.fxz.bean.factory.registory.BeanDefinitinRegistry;
import com.fxz.bean.utils.DocumentReader;
import org.dom4j.Document;

import java.io.InputStream;

/**
 * 读取xml并将bean注册到工厂
 *
 * @author Fxz
 * @version 1.0
 * @date 2021-08-12 19:59
 */
public class XmlBeanDefinitionReader {

    private BeanDefinitinRegistry beanDefinitinRegistry;

    public XmlBeanDefinitionReader(BeanDefinitinRegistry beanDefinitinRegistry) {
        this.beanDefinitinRegistry = beanDefinitinRegistry;
    }

    public void loadBeanDefinitions(InputStream inputStream) {
        Document document = DocumentReader.createDocument(inputStream);
        DefaultBeanDefinitionDocumentReader defaultBeanDefinitionDocumentReader = new DefaultBeanDefinitionDocumentReader(beanDefinitinRegistry);
        defaultBeanDefinitionDocumentReader.registerBeanDefinitions(document.getRootElement());
    }
}
